#include <typescommon.h>
#include <genrand.h>
#include <pthread.h>
#include "voidqueue.h"


#define QUE_VOID_CHECK_SIZE 10
int main(int argc, char **argv)
{
    struct arrayQueueManagerStruct tmpque;
    int *tmpvoidp;
    int tmpflag = 0;
    voidQueueInit(&tmpque, QUE_VOID_CHECK_SIZE);

    for (int i = 0; i < QUE_VOID_CHECK_SIZE; i++)
    {
        tmpvoidp = malloc(sizeof(int));
        tmpvoidp[0] = i;
        tmpflag = voidQueuePush(&tmpque, tmpvoidp);
        if(tmpflag < 0)
        {
            logerror("push error, and free data");
            free(tmpvoidp);
        }
        // logdebug("count=%lu,remain=%lu", voidQueueCount(&tmpque), voidQueueRemain(&tmpque));

        tmpvoidp = malloc(sizeof(int));
        tmpvoidp[0] = i + 1000;
        tmpflag = voidQueuePush(&tmpque, tmpvoidp);
        if(tmpflag < 0)
        {
            logerror("push error, and free data");
            free(tmpvoidp);
        }
        // logdebug("count=%lu,remain=%lu", voidQueueCount(&tmpque), voidQueueRemain(&tmpque));

        tmpflag = voidQueuePop(&tmpque, (void **)&tmpvoidp);
        if(tmpflag < 0)
        {
            logerror("pop has no data");
            continue;
        }
        logdebug("get data:%d", tmpvoidp[0]);
        free(tmpvoidp);
        // logdebug("count=%lu,remain=%lu", voidQueueCount(&tmpque), voidQueueRemain(&tmpque));
    }
    
    voidQueueFree(&tmpque);

    while(voidQueuePop(&tmpque, (void **)&tmpvoidp) >= 0)
    {
        logdebug("remain data:%d", tmpvoidp[0]);
        free(tmpvoidp);
    }

    voidQueueFree(&tmpque);
    return 1;
}




